﻿using System;

namespace CoreLib.NUnit.Constraints
{
    public class ThrowsExceptionConstraint<TException> : ActionConstraint where TException : Exception
    {
        private string _message = string.Empty;

        protected override bool Matches( Action actualAction )
        {
            try
            {
                actualAction();
            }
            catch( TException )
            {
                return true;
            }
            _message = string.Format( "Didn't throw {0}", typeof( TException ).FullName );
            return false;
        }

        protected override string GetMessage()
        {
            return _message;
        }
    }
}
